package it.enrico.mangamania.inventario.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FormHandler;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormSubmitEvent;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

@SuppressWarnings("deprecation")
public class FileUpload extends VerticalPanel {

	final FormPanel form = new FormPanel();
	VerticalPanel holder = new VerticalPanel();
	FileUpload upload = new FileUpload();

	public FileUpload() {
		
		
		// inizializzazione form per l'esportazione
		form.setEncoding(FormPanel.ENCODING_MULTIPART);
		form.setMethod(FormPanel.METHOD_POST);
		form.addStyleName("table-center");
		form.addStyleName("demo-panel-padded");
		form.setWidth("275px");
		
		upload.
		holder.add(upload);

		holder.add(new HTML("<hr />"));

		holder.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT);
		holder.add(new Button("Submit", new ClickHandler()
		{
		
		public void onClick(ClickEvent event) {
			form.submit();
		}
		}));

		form.add(holder);
		form.setAction("url");

		form.addFormHandler(new FormHandler()
		{
		public void onSubmit(FormSubmitEvent event)
		{
		// if (something_is_wrong)
		// {
		// Take some action
		// event.setCancelled(true);
		// }
		}

		public void onSubmitComplete(FormSubmitCompleteEvent event)
		{
			Window.alert(event.getResults());
		}
		});
	RootPanel.get("demo").add(form);
	}

}
